package main

import (
	"log"
)

import (
	"github.com/lxn/walk"
    . "github.com/lxn/walk/declarative"
)

var (
    mainwindow *walk.MainWindow
    webview *walk.WebView
)

func initmainwindow(){
	var (
        //container *walk.Container
		//widgetlist *walk.WidgetList
		webview	*walk.WebView
        err error
	)
	//webview,err=walk.NewWebView(mainwindow)	//设置父窗体是mw
    //mainwindow,err=walk.NewMainWindow()
    if err != nil {
        log.Println("生成窗体出错了")
    }
    err = (MainWindow{
        AssignTo: &mainwindow,
		Title:    "窗口编程学习",
		//ScreenCenter: true, // 屏幕居中不能用
		MinSize: Size{300, 260},
        Layout:   VBox{MarginsZero: true},
		Children: []Widget{
			WebView{
				AssignTo:     &webview,
				Name:         "webview",
				URL:          "http://127.0.0.1:8080/myddc",
				//OnURLChanged: mw.t1, //mw.t2, //响应webview的URL改变事件
			},
        },
    }.Create());
    if err != nil {
		log.Fatal(err)
	}
    //webview.SetURL("http://127.0.0.1:8080/myddc")
	/*webview.URLChanged().Attach(func(){
		//change_url, err = webview.URL()             //取得webview的URL
		//url_path, err := url.Parse(change_url) //分析URL，取出Path
		log.Println("刷新了网页事件，URL：")//, change_url, "\n URL path:", url_path.Path)
	})*/
}